package com.tengju.support.domain.model.resource;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;

@AllArgsConstructor
public enum ResourceOrientation {

    NONE(1,"普通用户"),
    CITY_STAR_ONE(2,"城市服务商1星"),
    CITY_STAR_TWO(3,"城市服务商2星"),
    CITY_STAR_THREE(4,"城市服务商3星"),
    CITY_STAR_FOUR(5,"城市服务商4星"),
    EC(6,"大区运营商EC"),
    SEC(7,"大区运营商SEC"),
    EEC(8,"大区运营商EEC");

    private Integer value;
    private String desc;

    @JsonValue
    public Integer getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    @JsonCreator
    public static ResourceOrientation fromVal(Integer val) {
        for (ResourceOrientation type : values()) {
            if (type.value.equals(val)) {
                return type;
            }
        }
        return null;
    }

    public static ResourceOrientation fromName(String name) {
        for (ResourceOrientation type : values()) {
            if (type.name().equals(name)) {
                return type;
            }
        }
        return null;
    }

    public static ResourceOrientation fromStarLevel(StarLevel starLevel) {
        switch (starLevel) {
            case EC:
                return EC;
            case EEC:
                return EEC;
            case SEC:
                return SEC;
            case NONE:
                return NONE;
            case CITY_STAR_ONE:
                return CITY_STAR_ONE;
            case CITY_STAR_TWO:
                return CITY_STAR_TWO;
            case CITY_STAR_FOUR:
                return CITY_STAR_FOUR;
            case CITY_STAR_THREE:
                return CITY_STAR_THREE;
            default:
                return null;
        }
    }

}
